feat(reviews): tie reviews to user accounts #69
Merged
+1,230
−399
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #65.
Reviews now belong to the logged-in user instead of an anonymous ID stored in the browser. Anyone could create unlimited anonymous IDs before, so this also stops one person from leaving many reviews. It is the first part of the profile work:
User.reviewsis ready for the «Mine anmeldelser» section of the profile page.What
Database
review.user_id(FK toapp_user,ON DELETE CASCADE), one review per user per wine, and exactly one author per review (account or old anonymous student). An index for a user's reviews, newest first.API
saveReview,deleteReviewandmyReviewuse the user from the session (auth.requireUser()/currentUser()). TheuserIdarguments are removed: the author is never taken from the request.authoris the username, ornullfor old anonymous reviews (the frontend shows «Anonym student»). Usernames are loaded with a DataLoader; the password hash is never read.User.reviews(first, after)with the same pages as the wine search. Reviews are public, so it also works for other users' profiles later.toConnectionhelper shared by the wine search andUser.reviews.backend/vitest.config.ts: tests never use the database inbackend/.env.Frontend
myReview) is shown afterwards.useUserIdis removed.noValidate,aria-invalid,aria-describedby), focus on the first error, capital letters allowed in the username (sent in lowercase), andaria-disabledinstead ofdisabledso the button keeps focus. API errors about a field are shown at that field; the others withrole="alert"and the shared texts fromlib/errors.ts.E2E
e2e/support/graphql.ts: one GraphQL stub for all specs.Meanswers «not logged in» by default, and an operation without a stub fails instead of getting another operation's data.Landingquery, plus the sharedMe. New tests for «Logg inn» and the username in the menu.Docs
docs/api.md: reviews with login,User.reviews, error codes, database tests.docs/manual-testing.md: how to test login, reviews and other user data by hand, with a checklist for the coming lists.main(error handling PR) was merged into this branch. Conflicts inuseWineReviews.tsandStudentReviews.tsxwere resolved by keeping both changes: the new{ ok, error }result and the removeduserId.How it was tested
npm run checkfrom the rootTEST_DATABASE_URLagainst a separate test database (no skipped tests): login required, users cannot see or delete each other's reviews, the average follows at once, old anonymous reviews,User.reviewswith pages and an invalid cursornpm run e2e: all pass exceptfilters.spec.ts › filtrer, sorter, last på nytt, angre og nullstillon mobile. It fails onmainas well, without this PR (#NN)psqldocs/manual-testing.mdsections 1–5: register and login errors, staying logged in, reviews with two users in two windows, the API withcurl, keyboard onlySearchPage.test.tsx › sender ett søk etter at brukeren har skrevet ferdigsometimes fails when the whole suite runs, also onmain. It passes on its own (timing; separate issue)How to review
The commits are small and build on each other, so commit by commit is easiest:
feat(db): migrationfeat(api): reviews as the logged-in user, with API testsfeat(reviews): the interfacefeat(api):User.reviewsmainfix(auth): the auth formtest(e2e): shared GraphQL stubdocsTo try it:
npm run db:migrateinbackend/, then section 3 ofdocs/manual-testing.md.Not in this PR
studenttable, once nothing reads it.AI
Code, tests, docs, and pr-text were drafted and created along with Claude, then applied, run and checked commit by commit by me, including the manual tests above.